<?php

/**
 * This Validator checks if the values of the password- and the confirmPassword-fields are equal  
 * @author Clueth
 *
 */

class Somi_Validate_PasswordConfirmation extends Zend_Validate_Abstract {
 
        const NOT_MATCH = 'passwordConfirmationNotMatch';  
      
        protected $_messageTemplates = array(  
            self::NOT_MATCH => 'Der eingegebene Wert stimmt nicht mit dem Passwort ueberein.'  
        );  
     
        
       protected $_fieldsToMatch = array();  
     
       public function __construct($fieldsToMatch = array()) {  
           if (is_array($fieldsToMatch)) {  
               foreach ($fieldsToMatch as $field) {  
                   $this->_fieldsToMatch[] = (string) $field;  
               }  
           } else {  
               $this->_fieldsToMatch[] = (string) $fieldsToMatch;  
           }  
       }  
     
       
       public function isValid($value, $context = null) {  
           $value = (string) $value;  
           $this->_setValue($value);  
     
           $error = false;  
     
           foreach ($this->_fieldsToMatch as $fieldName) {  
               if (!isset($context[$fieldName]) || $value !== $context[$fieldName]) {  
                   $error = true;  
                   $this->_error(self::NOT_MATCH );  
                   break;  
               }  
           }  
     
           return !$error;  
       }  
   }  

?>